// 面板收放
let title_bars = $('.list-title');
let open = [];
let orgin_h = [];
let timer = null;
let title_bars_len = title_bars.length;
for(var i = 0;i < title_bars_len;i++){
    open[i] = true;
    orgin_h[i] = $(`.list-content:eq(${i})`).height();
}
title_bars.click(function(){
    let i = $(this).index('.list-title');
    $(`.pull:eq(${i})`).toggleClass('open');
    let content = $(`.list-content:eq(${i})`);
    let danwei_s = open[i] ? -10 : 10;
    let danwei_t = 200*danwei_s/orgin_h[i];
    if(!open[i]){
        content.css('display','block')
    }
    clearInterval(timer);
    timer = setInterval(function(){
        let h = content.height();
        h += danwei_s;
        if(h > orgin_h[i]){
            h = orgin_h[i];
            clearInterval(timer)
        }else if(h < 0){
            h = 0;
            content.css('display','none');
            clearInterval(timer)
        }
        content.height(h);
    },danwei_t);
    open[i] = !open[i];
});
// 版块颜色轮换
let color_arr = ['top-a','top-b','top-c','top-d'];
let module_info = document.querySelectorAll('.module-info');
let module_info_len = module_info.length;
for(let i = 0;i < module_info_len;i++){
  let j = i % 4;
  module_info[i].className += ' '+color_arr[j];
}
//收藏按钮
let collect_btn = $('.collect');
collect_btn.click(function(){
    let hover_tip = $('#hover-tip');
    let that = $(this);
    that.toggleClass('collected');
    $.ajax({
        url: 'ajax/follow.php',
        type: 'GET',
        dataType: 'json',
        data: {w: 'module',id: that.prop('id')},
    })
    .done(function(data) {
        let msg = data.sign == 'in'?'已收藏':'已取消'; 
        hover_tip.text(msg);
        hover_tip.fadeIn();
        setTimeout(function(){
            hover_tip.fadeOut();
        },1000)
    });
    
});